package com.hupo.dy07_springboot_01.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

@RestController//这是应该请求类
@ControllerAdvice//全局异常处理类
public class GlobalExceptionHandler {

    //@ExceptionHandler标记该方法可以捕获并处理特定类型的异常
    @ExceptionHandler(Exception.class)
    public String exception(Exception e) {
        e.printStackTrace();
        System.out.println("111");
        return "操作失败，稍后再试"+e.getMessage();
    }

    @ExceptionHandler(ArithmeticException.class)
    public String exception(ArithmeticException e){
        e.printStackTrace();
        return e.getMessage();
    }
}
